using System;
using System.Data;
using Utils;
using Utils.DatabaseUtils;
using System.Collections;


namespace QLBH
{
public class tblPhanQuyenUI
{ 
	private int idQuyen;
	public int IdQuyen
	{
		get { return idQuyen;}
		set { idQuyen = value;}
	}

	private int idNhomNguoiDung;
	public int IdNhomNguoiDung
	{
		get { return idNhomNguoiDung;}
		set { idNhomNguoiDung = value;}
	}

	private int idChucNang;
	public int IdChucNang
	{
		get { return idChucNang;}
		set { idChucNang = value;}
	}

	private int quyen;
	public int Quyen
	{
		get { return quyen;}
		set { quyen = value;}
	}

	public tblPhanQuyenUI() {}

	public tblPhanQuyenUI(int idQuyen, int idNhomNguoiDung, int idChucNang, int quyen)
	 {
		this.idQuyen = idQuyen;
 		this.idNhomNguoiDung = idNhomNguoiDung;
 		this.idChucNang = idChucNang;
 		this.quyen = quyen;
 	}

	public int Add(int idNhomNguoiDung, int idChucNang, int quyen)
	{
		try
		{
			int result = SqlHelper.ExecuteNonQuery(Common.Conn,"tblPhanQuyen_Add",idNhomNguoiDung,idChucNang,quyen);
			return result;
		}
		catch(Exception e) {return -1; }
	}

    public int AddRage(int idNhomNguoiDung, Hashtable htQuyen)
    {
        try
        {
            string xml = "<Data>";
            foreach (string key in htQuyen.Keys)
            {
                xml += "<Quyen Id=\"" + key + "\" Value=\"" + htQuyen[key] + "\" />";
            }

            xml += "</xml>";

            int result = SqlHelper.ExecuteNonQuery(Common.Conn, "tblPhanQuyen_AddRange", idNhomNguoiDung, xml, htQuyen.Count);
            return result;
        }
        catch (Exception e) { return -1; }
    }

	public int Update(int idQuyen, int idNhomNguoiDung, int idChucNang, int quyen)
	{
		try
		{
			int result = SqlHelper.ExecuteNonQuery(Common.Conn,"tblPhanQuyen_Update",idQuyen,idNhomNguoiDung,idChucNang,quyen);
			return result;
		}
		catch(Exception e) {return -1; }
	}

	public int Delete(int idQuyen)
	{
		try
		{
			int result = SqlHelper.ExecuteNonQuery(Common.Conn,"tblPhanQuyen_Delete",idQuyen);
			return result;
		}
		catch(Exception e) {return -1; }
	}

	public int DeleteAll()
	{
		try
		{
			int result = SqlHelper.ExecuteNonQuery(Common.Conn,"tblPhanQuyen_DeleteAll");
			return result;
		}
		catch(Exception e) {return -1; }
	}

	public DataSet Get(int idQuyen)
	{
		try
		{
			DataSet result = SqlHelper.ExecuteDataset(Common.Conn,"tblPhanQuyen_Get",idQuyen);
			return result;
		}
		catch(Exception e) {return null; }
	}

	public DataSet GetAll()
	{
		try
		{
			DataSet result = SqlHelper.ExecuteDataset(Common.Conn,"tblPhanQuyen_GetAll");
			return result;
		}
		catch(Exception e) {return null; }
	}

	public DataSet GetByIdNhomNguoiDung(int idNhomNguoiDung)
	{
		try
		{
			DataSet result = SqlHelper.ExecuteDataset(Common.Conn,"tblPhanQuyen_GetByIdNhomNguoiDung",idNhomNguoiDung);
			return result;
		}
		catch(Exception e) {return null; }
	}

	public DataSet GetByIdChucNang(int idChucNang)
	{
		try
		{
			DataSet result = SqlHelper.ExecuteDataset(Common.Conn,"tblPhanQuyen_GetByIdChucNang",idChucNang);
			return result;
		}
		catch(Exception e) {return null; }
	}

} 
}
